#include <stdio.h>
#include <string.h>
using namespace std;

#define INF 0x3f3f3f

int max, min;
char maxS[15], minS[15];
int n;
int a, b, c;
int tmp;
char str[15];

int main() {
	scanf("%d", &n);

	while (n!=-1) {
		max=-1; min=INF;		

		for (int i=0; i<n; i++) {
			scanf(" %s %d %d %d", str, &a, &b, &c);
			tmp = a*5+b*10+c*20;

			if (tmp>max) {
				strcpy(maxS, str); max=tmp;
			}
			if (tmp<min) {
				strcpy(minS, str); min=tmp;
			}
		}

		if (max==min) printf("All have the same amount.\n");
		else printf("%s has most, %s has least money.\n", maxS, minS);
		
		scanf("%d", &n);
	}

	return 0;
}	
